﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KinectGame;

namespace MemoGame
{
    public partial class MenuUI : KinectBaseForm
    {
        private IList<GameButton> gameButtons; 
        public MenuUI()
        {
            InitializeComponent();
        }

        public override void SetupForKinectMode()
        {
            base.SetupForKinectMode();
            this.btnOptions.Enabled = false; 
            this.gameButtons = new List<GameButton>();
            this.gameButtons.Add(btnStart);
            this.gameButtons.Add(btnHallOfFame);
            this.gameButtons.Add(btnCredits);
            this.gameButtons.Add(btnQuitGame);
            this.btnCredits.Click -= new System.EventHandler(this.btnCredits_Click);
            this.btnHallOfFame.Click -= new System.EventHandler(this.btnHallOfFame_Click);
            this.btnOptions.Click -= new System.EventHandler(this.btnOptions_Click);
            this.btnStart.Click -= new System.EventHandler(this.btnStart_Click);
            this.btnQuitGame.Click -= new System.EventHandler(this.btnQuitGame_Click);
        }

        public override void highlightButton(int horizontalIndex, int verticalIndex)
        {
            if (verticalIndex > 0) this.gameButtons[verticalIndex - 1].Unhighlight();
            this.gameButtons[verticalIndex].Highlight();
            if (verticalIndex < this.gameButtons.Count - 1) this.gameButtons[verticalIndex + 1].Unhighlight(); 
        }

        public override void Click(int horizontalIndex, int verticalIndex) 
        {
            if (verticalIndex == 0) startGame();
            if (verticalIndex == 1) showHallOfFame();
            if (verticalIndex == 2) showCredits();
            if (verticalIndex == 3) quitGame();
        }

        public override int SetHorizontalItemNumber()
        {
            return 1; 
        }

        public override int SetVerticalItemNumber()
        {
            return this.gameButtons.Count;
        }


        public void startGame()
        {
            //button1.H
            Game game = Game.getInstance();
            int size = game.GameSize;
            if (game.initiate(size))
            {
                game.startTimer();
                this.gameContext.ApplicationMode(this, game.GameUI, 1); 
            }
        }

        public void quitGame()
        {
            Console.WriteLine("THE END");
            this.gameContext.ApplicationClose();
        }

        public void showCredits()
        {
            Console.WriteLine("CREDITS");
            this.gameContext.ApplicationMode(this, new CreditsUI(), 2); 
        }

        public void showHallOfFame()
        {
            Console.WriteLine("HALL OF FAME");
            this.gameContext.ApplicationMode(this, new HallOfFameUI(), 3);
        }

        public void showOptions()
        {
            Console.WriteLine("OPTIONS");
            this.gameContext.ApplicationMode(this, new OptionsUI(), 2);
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            startGame();
        }

        private void btnOptions_Click(object sender, EventArgs e)
        {
            showOptions();
        }

        private void btnHallOfFame_Click(object sender, EventArgs e)
        {
            showHallOfFame();

        }

        private void btnCredits_Click(object sender, EventArgs e)
        {
            showCredits();
        }

        private void btnQuitGame_Click(object sender, EventArgs e)
        {
            quitGame();
        }
    }
}
